package com.sec.android.app.myfiles.feature.multiwindow;

import android.app.Activity;
import android.content.Context;
import android.graphics.Point;
import android.graphics.Rect;
import android.provider.Settings;
import android.view.Display;
import android.view.Surface;
import android.view.WindowManager;

import com.sec.android.app.myfiles.feature.MultiWindowMgr.WindowState;

public abstract class AbsMultiWindowImp {

    protected Activity mActivity;

    AbsMultiWindowImp(Activity activity) {
        mActivity = activity;
    }

    public WindowState getWindowState() {
        WindowState ret;
        boolean screenRotationLocked = Settings.System.getInt(mActivity.getContentResolver(),
                Settings.System.ACCELEROMETER_ROTATION, 0) == 0;

        if (screenRotationLocked) {
            ret = WindowState.PORTRAIT;
        } else {
            WindowManager wm = (WindowManager) mActivity.getSystemService(Context.WINDOW_SERVICE);
            Display display = wm.getDefaultDisplay();
            int rotation = display.getRotation();

            if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
                switch (rotation) {
                    case Surface.ROTATION_0:
                    case Surface.ROTATION_180:
                        ret = WindowState.PORTRAIT;
                        break;
                    default:
                        ret = WindowState.LANDSCAPE;
                        break;
                }
            } else {
                Point point = new Point();
                display.getSize(point);

                if (point.x < point.y) {
                    ret = WindowState.PORTRAIT;
                } else {
                    ret = WindowState.LANDSCAPE;
                }
            }
        }

        return ret;
    }

    public abstract boolean isMultiWindow();

    public abstract boolean isScaleWindow();

    public abstract Rect getRectInfo();
}
